/*
    <one line to give the library's name and an idea of what it does.>
    Copyright (C) 2013  Guillaume <email>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/


#ifndef MSDIRACS_H
#define MSDIRACS_H

#include <msScalarFunction.h>
#include <msSamplerExplicit.h>

namespace atomism
{
 

class msDiracs : public msScalarFunction
{ 
private:
       
      //!\name from msRegister 
      //@{
      static msRegistrar Registrar;
      static bool  isDiracsRegisteredInPython;
      static msRegister* createInstance() { return new msDiracs; }
      //@}
      
protected:      
      
     void registryInPython();

     void update()  {msScalarFunction::update();
                     };
	     
     msDiracs() : msScalarFunction(){
	             constructVar("msDiracs","Diracs","repromodel");
                     }    
             
public:
       
     static boost::shared_ptr<msDiracs> New(string unitexpr){
       
	       boost::shared_ptr<msDiracs> T( new msDiracs );
	       LOGGER_ENTER_FUNCTION_DBG("msScalarFunction::New(boost::shared_ptr<msGeneralizedCoordinates> unit)",T->getFullId());
	       T->initialize(); T->getYUnit().set(unitexpr); T->update();
	       LOGGER_EXIT_FUNCTION();
	       return T;
	       }
	       
       virtual boost::shared_ptr<msTreeMapper> clone() { 
            boost::shared_ptr<msScalarFunction> clone = New(""); 
	    clone->msTreeMapper::operator=(*this);					      
	    return clone;
            }  
            
       void initialize()  {  msScalarFunction::initialize();
			     declareChild<msSamplerExplicit >(Sampler,
							       msSamplerExplicit::New(),
							       "Sampler");
			     declareAttribute<vector<double> >(Values,"Values");
			    };
       boost::shared_ptr<msTreeMapper> setDiracSampler(boost::shared_ptr<msSamplerExplicit> sampler){
	      
		      msTreeMapper::update(Sampler,sampler);
		      return mySharedPtr();
		      }

       boost::shared_ptr<msSamplerExplicit> getSampler(){ return Sampler.getSharedPtr();
							  }  
	
       boost::shared_ptr<msTreeMapper> load(string filename);
					  
       void addDirac(const vector<double> coors,double value){
	 
	  Values.push_back(value);
	  Sampler->addSample(coors);
	  };
		      
       double evaluate(){return Values[Sampler->noOfScanned()-1];}
       
       size_t noOfValues() const {return Values.size();};
private:
    
       msChild<msSamplerExplicit> Sampler;
  
       vector<double> Values;
 };

}
#endif // MSDIRACS_H
